<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/css/amazeui.min.css" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css" />
		<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/myplugs/js/plugs.js"></script>
		<script src="${pageContext.request.contextPath}/js/layui.js"></script>
		<script type="text/javascript">
			//添加编辑弹出层
			function insertUser(title, id) {
				$.jq_Panel({
					title: title,
					iframeWidth: 500,
					iframeHeight: 300,
					url: "/user/insertUser"
				});
			}
			function updateUser(title,username) {
				console.log("username:"+username)
				$.jq_Panel({
					title: title,
					iframeWidth: 500,
					iframeHeight: 300,
					url: "/user/updateUser?username="+username
				});
			}
			function deleteUser(id){
				var datas={};
				datas.id=id;
				var r= confirm("确认删除？");
				if (r==true) {
					$.ajax({
						async: false,
						type: "POST",
						url: "/user/deleteUser",//注意路径
						data: datas,
						dataType: "json",
						success: function (data) {
							if (data.result == 'SUCCESS') {
								alert("删除成功！");
								window.location.reload();
							} else {
								alert("删除失败，失败原因【" + data.result + "】");
							}
						},
						error: function (data) {
							alert(data.result);
						}
					});
					return true;
				}
				else {
					return false;
				}


			}
		</script>
	</head>

	<body>
		<div class="admin-content-body">
			<div class="am-cf am-padding am-padding-bottom-0">
				<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理</strong><small></small></div>
			</div>

			<hr>

			<div class="am-g">
				<div class="am-u-sm-12 am-u-md-6">
					<div class="am-btn-toolbar">
						<div class="am-btn-group am-btn-group-xs">
							<button type="button" class="am-btn am-btn-default"  onclick="insertUser('新增用户',1)"><span class="am-icon-plus"></span> 新增</button>
						</div>
					</div>
				</div>
				<div class="am-u-sm-12 am-u-md-3">

				</div>
<%--				<div class="am-u-sm-12 am-u-md-3">--%>
<%--					<div class="am-input-group am-input-group-sm">--%>
<%--						<input type="text" class="am-form-field" placeholder="请输入用户名">--%>
<%--						<span class="am-input-group-btn">--%>
<%--            <button class="am-btn am-btn-default" type="button">搜索</button>--%>
<%--          </span>--%>
<%--					</div>--%>
<%--				</div>--%>
			</div>
			<div class="am-g">
				<div class="am-u-sm-12">
					<form class="am-form">
						<table class="am-table am-table-striped am-table-hover table-main">
							<thead>
								<tr>
									<th class="table-id">ID</th>
									<th class="table-type">用户名</th>
									<th class="table-author am-hide-sm-only">密码</th>
									<th class="table-set">操作</th>
								</tr>
							</thead>
							<tbody>
							<c:forEach items="${userPageInfo.list}" var="u">
								<tr>
									<td>${u.id}</td>
									<td>${u.username}</td>
									<td class="am-hide-sm-only">${u.password}</td>
									<td>
										<div class="am-btn-toolbar">
											<div class="am-btn-group am-btn-group-xs">
												<button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="updateUser( '修改用户','${u.username}')"><span class="am-icon-pencil-square-o"></span> 编辑</button>
												<button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="return deleteUser(${u.id})"><span class="am-icon-trash-o" ></span> 删除</button>
											</div>
										</div>
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
						<div class="am-cf">
							共 ${userPageInfo.total} 条记录
							<div class="am-fr">
								<ul class="am-pagination">
									<li>
										<a href="/user/show_user_page?pageNum=${userPageInfo.navigateFirstPage}">首页</a>
									</li>
									<li class="am-active">
										<a href="/user/show_user_page?pageNum=${userPageInfo.prePage}">«</a>
									</li>
									<li class="am-active">
										<a href="/user/show_user_page?pageNum=${userPageInfo.pageNum}">${userPageInfo.pageNum}</a>
									</li>
									<li>
										<a href="/user/show_user_page?pageNum=${userPageInfo.nextPage}">»</a>
									</li>
									<li>
										<a href="/user/show_user_page?pageNum=${userPageInfo.navigateLastPage}">${userPageInfo.pages}</a>
									</li>
								</ul>
							</div>
						</div>
						<hr>
					</form>
				</div>
			</div>
		</div>
	</body>
</html>